package com.facebook.imageformat;

import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;

public final class GifFormatChecker
{
  private static final byte[] FRAME_HEADER_END_1 = { 0, 44 };
  private static final byte[] FRAME_HEADER_END_2 = { 0, 33 };
  private static final int FRAME_HEADER_SIZE = 10;
  private static final byte[] FRAME_HEADER_START = { 0, 33, -7, 4 };

  @VisibleForTesting
  static boolean circularBufferMatchesBytePattern(byte[] paramArrayOfByte1, int paramInt, byte[] paramArrayOfByte2)
  {
    Preconditions.checkNotNull(paramArrayOfByte1);
    Preconditions.checkNotNull(paramArrayOfByte2);
    if (paramInt >= 0);
    for (boolean bool = true; ; bool = false)
    {
      Preconditions.checkArgument(bool);
      if (paramArrayOfByte2.length <= paramArrayOfByte1.length)
        break;
      return false;
    }
    for (int i = 0; ; i++)
    {
      if (i >= paramArrayOfByte2.length)
        break label69;
      if (paramArrayOfByte1[((i + paramInt) % paramArrayOfByte1.length)] != paramArrayOfByte2[i])
        break;
    }
    label69: return true;
  }

  public static boolean isAnimated(InputStream paramInputStream)
  {
    byte[] arrayOfByte = new byte[10];
    int j;
    label102: 
    do
    {
      try
      {
        paramInputStream.read(arrayOfByte, 0, 10);
        int i = 0;
        j = 0;
        while (paramInputStream.read(arrayOfByte, i, 1) > 0)
        {
          if ((circularBufferMatchesBytePattern(arrayOfByte, i + 1, FRAME_HEADER_START)) && ((circularBufferMatchesBytePattern(arrayOfByte, i + 9, FRAME_HEADER_END_1)) || (circularBufferMatchesBytePattern(arrayOfByte, i + 9, FRAME_HEADER_END_2))))
            break label102;
          i = (i + 1) % arrayOfByte.length;
        }
      }
      catch (IOException localIOException)
      {
        throw new RuntimeException(localIOException);
      }
      return false;
      j++;
    }
    while (j <= 1);
    return true;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.facebook.imageformat.GifFormatChecker
 * JD-Core Version:    0.6.2
 */